<?php
/**
 * Created by PhpStorm.
 * User: 18879810386
 * Date: 2016/10/26
 * Time: 20:13
 */function dbinit()
{$link=mysqli_connect('localhost','root','','itcast');
if(!$link){die('连接数据库失败！'.mysqli_error($link));}
mysqli_query($link,'set names utf8');
return $link;}
function query($link,$sql)
{if ($result=mysqli_query($link,$sql))
    return $result;
else{echo 'sql执行失败:<br>';
    echo '错误的sql为:',$sql,'<br>';
    echo '错误的代码为:',mysqli_errno($link),'<br>';
    echo '错误的信息为:',mysqli_error($link),'<br>';}
}
function fetchAll($link,$sql)
{if($result=query($link,$sql))
{$rows=array();
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){$rows=$row;}
mysqli_free_result($result);
return $rows;}
else return false;
}
function fetchrow($sql,$link)
{if($result=query($link,$sql))
{$row=mysqli_fetch_array($result);
return $row;}
else {return false;}
}
function safeHandle($link,$data)
{$data=htmlspecialchars($link,$data);
$data=mysqli_real_escape_string($link,$data);
return $data;}


